﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.ServiceModel.Syndication;
using System.Xml;
using PBDesk.com.Extension.FeedsAggregator;

namespace PBDesk.com.Controllers
{
    public class RssController :  Controller
    {
        public ActionResult Index()
        {
            SyndicationFeed feed = FeedHelper.GetPBDeskComRss();
            return new RssActionResult() { Feed = feed };
        }
    }

    public class RssActionResult : ActionResult
    {
        public SyndicationFeed Feed { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/rss+xml";

            Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(Feed);
            using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
            {
                rssFormatter.WriteTo(writer);
            }
        }

    }
}
